package cn.edu.scau.cmi.zhangjunjia.adapter;

import java.util.ArrayList;
import java.util.List;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.TextField;

import javafx.scene.control.TextArea;

public class AdapterController {
	@FXML
	private TextField classId;
	@FXML
	private TextField className;
	@FXML
	private TextField objectId;
	@FXML
	private TextField objectName;
	@FXML
	private Button classAdd;
	@FXML
	private Button objectAdd;
	@FXML
	private TextArea classMsg;
	@FXML
	private TextArea objectMsg;
	
	List<Student> studentList1 = new ArrayList<Student>();
	List<Student> studentList2 = new ArrayList<Student>();
	
	public void addClass() {
		String idString = classId.getText();
		String name = className.getText();
		int id = Integer.valueOf(idString);
		studentList1.add(new Student(id, name));
		Target adapterOfClass = new AdapterOfClass();
		List sortedList = adapterOfClass.quickSort(studentList1);
		String msg = "";
		for(int i = 0; i < sortedList.size(); i++) {
			msg = msg + sortedList.get(i);
		}
		classMsg.setText(msg);
	}
	
	public void addObject() {
		String idString = objectId.getText();
		String name  = objectName.getText();
		int id = Integer.valueOf(idString);
		studentList2.add(new Student(id, name));
		Target adaptOfObject = new AdapterOfObject(studentList2);
		List sortedList = adaptOfObject.quickSort(studentList2);
		String msg = "";
		for(int i = 0; i < sortedList.size(); i++) {
			msg = msg + sortedList.get(i);
		}
		objectMsg.setText(msg);
	}

}